---
title: Spec - howl.breadcrumbs
tags: spec
---
<div class="spec-group spec-group-1">

<h1 id="howl.breadcrumbs">howl.breadcrumbs</h1>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">editor</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">,</span><span class="w"> </span><span class="n">old_tolerance</span><span class="w">

</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">text</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="k">with</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
    </span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">text</span><span class="w">

</span><span class="n">setup</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Window</span><span class="o">!</span><span class="w">
  </span><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">app</span><span class="o">\</span><span class="n">new_editor</span><span class="o">!</span><span class="w">
  </span><span class="n">cursor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">cursor</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">init</span><span class="o">!</span><span class="w">
  </span><span class="n">old_tolerance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_tolerance</span><span class="w">

</span><span class="n">teardown</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_tolerance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">old_tolerance</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="o">\</span><span class="n">destroy</span><span class="o">!</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_tolerance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="w">

</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">clear</span><span class="o">!</span></code></pre>

<div class="spec-group spec-group-2">

<h2 id="drop(opts)">drop(opts)</h2>

<h4 id="accepts-a-file-and-a-pos">accepts a file and a pos</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">:file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="ss">:file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span></code></pre>


<h4 id="accepts-a-file-path-and-a-pos">accepts a file path and a pos</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">:file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="ss">file:</span><span class="w"> </span><span class="nc">File</span><span class="p">(</span><span class="n">file</span><span class="p">),</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span></code></pre>


<h4 id="accepts-a-buffer-and-a-pos">accepts a buffer and a pos</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">
  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="p">.</span><span class="n">file</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="p">.</span><span class="n">buffer_marker</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(when-a-buffer-is-present)">(when a buffer is present)</h3>

<h4 id="sets-a-marker-in-the-buffer-pointing-to-the-crumb">sets a marker in the buffer pointing to the crumb</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="p">.</span><span class="n">buffer_marker</span><span class="w">

</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="p">.</span><span class="n">buffer_marker</span><span class="w">
</span><span class="n">marker_buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">markers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">marker_buffer</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="n">m</span><span class="p">.</span><span class="n">name</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">markers</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">markers</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">start_offset</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">markers</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_offset</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-opts-is-missing)">(when opts is missing)</h3>

<h4 id="adds-a-crumb-for-the-current-buffer-and-position">adds a crumb for the current buffer and position</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1234\n6789'</span><span class="w">
  </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="o">!</span><span class="w">
  </span><span class="n">crumb</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">crumb</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">crumb</span><span class="p">.</span><span class="n">buffer_marker</span><span class="p">.</span><span class="n">buffer</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">crumb</span><span class="p">.</span><span class="n">file</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-forward-crumbs-exists)">(when forward crumbs exists)</h3>

<h4 id="invalidates-all-such-crumbs-and-buffer-markers">invalidates all such crumbs and buffer markers</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">9</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w"> </span><span class="c1">-- loc 3</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w"> </span><span class="c1">-- loc 2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="w">

</span><span class="n">markers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="p">.</span><span class="n">start_offset</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">b</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">find</span><span class="p">({})]</span><span class="w">
</span><span class="nb">table.sort</span><span class="w"> </span><span class="n">markers</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">markers</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(----context-'(tolerance-handling)',
)">(    context '(tolerance handling)',
)</h3>

<h4 id="merges-crumbs-when-their-distance-is-within-the-tolerance">merges crumbs when their distance is within the tolerance</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="s1">'123456789\n'</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_tolerance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="w">

</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">pos</span><span class="w">
</span><span class="n">markers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="p">.</span><span class="n">start_offset</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">find</span><span class="p">({})]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">6</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">markers</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">12</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">12</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">pos</span><span class="w">
</span><span class="n">markers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="p">.</span><span class="n">start_offset</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">buf</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">find</span><span class="p">({})]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="mi">12</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">markers</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(house-cleaning-according-to-breadcrumb_limit)">(house cleaning according to breadcrumb_limit)</h3>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">old_limit</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">old_limit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_limit</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_limit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">

</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_limit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">old_limit</span></code></pre>


<h4 id="purges-old-crumbs-according-to-breadcrumb_limit">purges old crumbs according to breadcrumb_limit</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">},</span><span class="w"> </span><span class="p">[</span><span class="n">c</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">]</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="crumb-cleaning">crumb cleaning</h2>

<h4 id="removes-duplicate-crumbs">removes duplicate crumbs</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">markers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="p">{}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">markers</span></code></pre>


<h4 id="reduces-unnecessary-loops">reduces unnecessary loops</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="clear">clear</h2>

<h4 id="invalidates-any-existing-crumbs-(buffer-markers-and-crumbs)">invalidates any existing crumbs (buffer markers and crumbs)</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">crumb</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">previous</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">clear</span><span class="o">!</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">find</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="n">crumb</span><span class="p">.</span><span class="n">buffer_marker</span><span class="p">.</span><span class="n">name</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="go_back">go_back</h2>

<h4 id="inserts-a-crumb-if-needed-before-going-back">inserts a crumb if needed before going back</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
  </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- at pos 5</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w"> </span><span class="c1">-- at breadcrumbs location 2</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w"> </span><span class="c1">-- with two forward crumbs</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- the old one</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- and the newly inserted</span><span class="w">

  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- at pos 3</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w"> </span><span class="c1">-- at breadcrumbs location 1</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w"> </span><span class="c1">-- only three forward crumbs</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">},</span><span class="w"> </span><span class="p">[</span><span class="n">c</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">]</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(with-a-buffer-and-pos-available)">(with a buffer and pos available)</h3>

<h4 id="opens-the-buffer-and-set-the-current-position">opens the buffer and set the current position</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>


<h4 id="uses-a-buffer-marker-for-positioning-to-account-for-updates">uses a buffer marker for positioning to account for updates</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">b</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'xx'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-a-file-and-pos-available)">(with a file and pos available)</h3>

<h4 id="opens-the-file-and-sets-the-current-position">opens the file and sets the current position</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">file:</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">file</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-the-buffer-has-been-collected)">(when the buffer has been collected)</h3>

<h4 id="falls-back-to-the-file-when-available">falls back to the file when available</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1234\n6789'</span><span class="w">
  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">
  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">file:</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
  </span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">file</span></code></pre>


<h4 id="moves-to-the-crumb-before-if-present">moves to the crumb before if present</h4>

<pre class="highlight moonscript"><code><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'buffer1'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">

</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'buffer2'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">

</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">

</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(tolerance-handling)">(tolerance handling)</h3>

<h4 id="moves-beyond-the-previous-crumb-if-it-is-within-the-distance">moves beyond the previous crumb if it is within the distance</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="s1">'1234567890'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_tolerance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">10</span><span class="w">
</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">12</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="go_forward">go_forward</h2>

<h4 id="inserts-a-crumb-if-needed-before-going-forward">inserts a crumb if needed before going forward</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
  </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">

  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w"> </span><span class="c1">-- with three forward crumbs</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w"> </span><span class="c1">-- at breadcrumbs location 1</span><span class="w">

  </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- at pos 5</span><span class="w">

  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w"> </span><span class="c1">-- with two forward crumbs</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w"> </span><span class="c1">-- with location thus = 3</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- old back crumb</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- newly inserted</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- old forward crumb</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">4</span><span class="p">].</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- old forward crumb</span><span class="w">

  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="c1">-- at pos 5</span><span class="w">

  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="(with-a-buffer-and-pos-available)">(with a buffer and pos available)</h3>

<h4 id="opens-the-buffer-and-set-the-current-position">opens the buffer and set the current position</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span></code></pre>


<h4 id="uses-a-buffer-marker-for-positioning-to-account-for-updates">uses a buffer marker for positioning to account for updates</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">b</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="s1">'xx'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(with-a-file-and-pos-available)">(with a file and pos available)</h3>

<h4 id="opens-the-file-and-sets-the-current-position">opens the file and sets the current position</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">file:</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">file:</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">file</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(when-the-buffer-has-been-collected)">(when the buffer has been collected)</h3>

<h4 id="falls-back-to-the-file-when-available">falls back to the file when available</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1234\n6789'</span><span class="w">
  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">''</span><span class="w">
  </span><span class="n">b</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">file:</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">file:</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
  </span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">file</span></code></pre>


<h4 id="moves-to-the-crumb-after-if-present">moves to the crumb after if present</h4>

<pre class="highlight moonscript"><code><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'buffer1'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">4</span><span class="w">

</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'buffer2'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">

</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">

</span><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="(tolerance-handling)">(tolerance handling)</h3>

<h4 id="moves-beyond-the-next-crumb-if-it-is-within-the-distance">moves beyond the next crumb if it is within the distance</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="s1">'1234567890'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">breadcrumb_tolerance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_back</span><span class="o">!</span><span class="w">

</span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">go_forward</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="location">location</h2>

<h4 id="points-to-the-current-crumb-position">points to the current crumb position</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="s1">'1234567890'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>


<h4 id="can-be-assigned-to-move-to-a-specific-location">can be assigned to move to a specific location</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="p">(</span><span class="s1">'1234567890'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">cursor</span><span class="p">.</span><span class="n">pos</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id=".trail">.trail</h2>

<h4 id="contains-a-list-of-breadcrumbs">contains a list of breadcrumbs</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">:file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
  </span><span class="n">crumbs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">crumbs</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">pos</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">crumbs</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">buffer_marker</span><span class="p">.</span><span class="n">buffer</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="ss">:file</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="p">},</span><span class="w"> </span><span class="n">crumbs</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>


<h4 id="is-automatically-cleaned">is automatically cleaned</h4>

<pre class="highlight moonscript"><code><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">
</span><span class="n">crumbs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">crumbs</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">crumbs</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">pos</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(when-a-buffer-is-closed)">(when a buffer is closed)</h3>

<h4 id="removes-any-crumbs-missing-a-file-reference">removes any crumbs missing a file reference</h4>

<pre class="highlight moonscript"><code><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">app</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">
</span><span class="n">b2</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
</span><span class="n">b2</span><span class="p">.</span><span class="n">modified</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">app</span><span class="o">\</span><span class="n">close_buffer</span><span class="w"> </span><span class="n">b2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">},</span><span class="w"> </span><span class="p">[</span><span class="n">c</span><span class="p">.</span><span class="n">pos</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">]</span></code></pre>


<h4 id="clears-any-buffer-references-for-crumbs-with-a-file-reference">clears any buffer references for crumbs with a file reference</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
  </span><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
  </span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">app</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">
  </span><span class="n">b2</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
  </span><span class="n">app</span><span class="o">\</span><span class="n">close_buffer</span><span class="w"> </span><span class="n">b2</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">buffer_marker</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">trail</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>


<h4 id="moves-the-current-location-down-as-necessary">moves the current location down as necessary</h4>

<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
  </span><span class="n">b1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789'</span><span class="w">
  </span><span class="n">b2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">app</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">
  </span><span class="n">b2</span><span class="p">.</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b1</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">5</span><span class="w">
  </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">b2</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">7</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span><span class="w">
  </span><span class="n">app</span><span class="o">\</span><span class="n">close_buffer</span><span class="w"> </span><span class="n">b2</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">location</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h3 id="(memory-management)">(memory management)</h3>

<h4 id="keeps-weak-references-to-buffers">keeps weak references to buffers</h4>

<pre class="highlight moonscript"><code><span class="n">holder</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'123456789\nabcdefgh'</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">

</span><span class="n">breadcrumbs</span><span class="p">.</span><span class="n">drop</span><span class="w"> </span><span class="ss">buffer:</span><span class="w"> </span><span class="n">holder</span><span class="p">.</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="ss">pos:</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="nb">collectgarbage</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">holder</span><span class="p">.</span><span class="n">buffer</span></code></pre>

</div>
</div>
